// 导入组件
import CodeBlock from "./CodeBlock.vue";
import { createNllNode } from "../../nodeUtils";
import { MarkerType, VueFlow, useVueFlow } from "@vue-flow/core";
// const { removeEdges, addNodes, addEdges } = useVueFlow();
// 导出组件
export default {
  id: "code-block",
  label: "js代码块",
  component: CodeBlock,
  // 处理节点添加事件
  onNodeAdd: (currentEdge, { removeEdges, addNodes, addEdges }) => {
    const newNodeId = `node-${Date.now()}`;

    const blckNode = {
      id: newNodeId,
      type: "code-block",
      data: {
        code: "",
      },
      position: { x: 0, y: 0 },
    };

    // 添加节点
    addNodes([blckNode]);

    // 删除原有的边
    removeEdges([currentEdge.id]);

    // 添加新的边
    addEdges([
      {
        id: `edge-${currentEdge.source}-${blckNode.id}`,
        source: currentEdge.source,
        target: blckNode.id,
        targetHandle: "in",
        type: "add-node",
        style: currentEdge.style,
        // 动画
        animated:  currentEdge.source == 'start',
      },
      {
        id: `edge-${blckNode.id}-${currentEdge.target}`,
        source: blckNode.id,
        targetHandle: "out",
        target: currentEdge.target,
        type: "add-node",
        label: "yes",
        style: currentEdge.style,
      },
    ]);
  },
};
